package cn.fan.whale.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.fan.whale.entity.dto.BaseReturnDto;
import cn.fan.whale.entity.po.DepartmentEntity;
import cn.fan.whale.service.DepartmentService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
@CrossOrigin
@SaCheckLogin
public class DepartmentController {

    private final DepartmentService departmentService;

    public DepartmentController(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @GetMapping("/find")
    public BaseReturnDto find(DepartmentEntity departmentEntity) {
        List<DepartmentEntity> list = departmentService.selectBySelective(departmentEntity);
        return BaseReturnDto.success(list);
    }

    @SaCheckPermission("system.department:save")
    @PostMapping("/save")
    public BaseReturnDto save(@RequestBody DepartmentEntity departmentEntity) {
        departmentService.save(departmentEntity);
        return BaseReturnDto.success(BaseReturnDto.RESP_SUCCESS_CODE, "操作成功");
    }

    @SaCheckPermission("system.department:update")
    @PostMapping("/update")
    public BaseReturnDto update(@RequestBody DepartmentEntity departmentEntity) {
        departmentService.update(departmentEntity);
        return BaseReturnDto.success(BaseReturnDto.RESP_SUCCESS_CODE, "操作成功");
    }

    @SaCheckPermission("system.department:delete")
    @GetMapping("/delete")
    public BaseReturnDto delete(Integer deptId) {
        departmentService.delete(deptId);
        return BaseReturnDto.success(BaseReturnDto.RESP_SUCCESS_CODE, "操作成功");
    }
}
